<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Blog Design</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<?php
/**
 * Created by PhpStorm.
 * User: Dale
 * Date: 2017/7/4
 * Time: 10:04
 */

$dsn = 'mysql:dbname=MyBlog;host=192.168.76.11';
$user = 'root';
$password = '123456';
try {
	$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
	echo 'Connection failed: ' . $e->getMessage();
}

$sql="SELECT * FROM tb_article";

$sql2="SELECT * FROM tb_classes";

$statement = $dbh->query($sql);
if($statement === false ){
	die('SQL出错'.$dbh->errorInfo()[2]);
}
$rs_list = $statement->fetchAll(PDO::FETCH_ASSOC);

$statement = $dbh->query($sql2);
if($statement === false ){
	die('SQL出错'.$dbh->errorInfo()[2]);
}
$rs_classes = $statement->fetchAll(PDO::FETCH_ASSOC);

?>
<body>
<div id="header">
	<span class="logo">That is Amazing!</span>
	<ul id="menu">
		<li><a href="index.php"><img src="images/but1.gif" alt="" width="64" height="42" /></a></li>
		<li><a href="index.php"><img src="images/but2.gif" alt="" width="108" height="42" /></a></li>
		<li><a href="index.php"><img src="images/but3.gif" alt="" width="93" height="42" /></a></li>
	</ul>
	<img src="images/spacer.gif" alt="setalpm" width="120" height="120" border="0" usemap="#Map" class="rss" />
	<map name="Map">
		<area shape="circle" coords="60,60,63" href="">
	</map>
</div>
<div id="content">
	<div id="posts">

		<?php
		foreach ($rs_list as $KEY) {
			echo '<div class="post">
					      <h2><a style="text-decoration:none;color: #474747;" href="article.php?id='.$KEY['ID'].'">';
			echo $KEY['Title'];

			echo '</a> </h2>
					<div>
						<span class="date">';
			echo substr($KEY['PublishTime'], 0, 10);
			echo '</span>
						<span class="categories">
			              in: ';
			foreach ($rs_classes as $KEY1) {
				if($KEY1['ClassID'] == $KEY['ClassID'])
					echo $KEY1['ClassName'];
			}
			echo'</span>
					</div>
					<div class="description">
						<p>
							';
			echo $KEY['Abstract'];echo '
						</p>
					</div>
					<p class="comments">
						Comments -
						<a href="">17</a>
						<span>|</span>
						<a href="index.php">
							Continue Reading
						</a>
					</p>
				</div>';
		}
		?>



</div>
	<div id="sidebar">
		<div id="search">
			<input type="text" placeholder="Search" > <a href=""><img src="images/go.gif" alt="" width="26" height="26" /></a>
		</div>

	</div>
	<div class="list">
		<img src="images/title1.gif" alt="" width="186" height="36" />
		<ul>
			<?php
			foreach ($rs_classes as $KEY1) {
					echo '<li><a href="class.php?classid='.$KEY1['ClassID'].'">'.$KEY1['ClassName'].'</a></li>';
			}

			?>
		</ul>
<div id="footer">
	<p>Copyright &copy;. All rights reserved.</p>
</div>
<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div></body>
</html>